package com.hzx.shoot;

import com.hzx.shoot.img.Images;

import java.awt.*;
import java.awt.image.BufferedImage;

/*
 * 天空类
 * */
public class Sky extends FlyingObject {
    private int speed;

    //不需要x 因为背景图不会变
    public int y1;

    @Override
    public String toString() {
        return "Sky{" +
                "speed=" + speed +
                ", wdith=" + wdith +
                ", height=" + height +
                ", x=" + x +
                ", y=" + y +
                '}';
    }

    //注意子类和父类的 super()用法 因为父类没有无参构造
    public Sky() {
        super(0, 0, 512, 768);
        y1 = -this.height;//当前对象的高
        speed = 2;
    }

    @Override
    public BufferedImage getImage() {
        return Images.skyImage;
    }

    @Override
    public void step() {
        this.y += speed;//第一张图
        this.y1 += speed;
        //第一张图片出界 将y的值拉到负高的值等待
        if (this.y > this.height) {
            this.y = -this.height;
        }
        if (this.y1 > this.height) {
            this.y1 = -this.height;
        }

    }

    //画背景的方法
    public void paint(Graphics g) {
        g.drawImage(this.getImage(), this.x, this.y, null);
        g.drawImage(this.getImage(), this.x, this.y1, null);
    }
}
